<?php
class Portfoliomanager_Model_Pagedecision implements Portfoliomanager_Model_Mainable{
    
    private $action_handler;
    private $core_controller_csrftoken;
    private $get_account_status;
    private $get_access_level;
    private $get_subcategories;
    private $get_images;

    public function main(array $variables = null) {
        switch($variables['get']['page']){
            case 'dodaj-portfolio':
                return $this->add_portfolio($variables);
                break;
            case 'wstaw-portfolio':
                return $this->insert_portfolio($variables);
                break;
            case 'edytuj-portfolio':
                return $this->edit_portfolio($variables);
                break;
            case 'aktualizuj-portfolio':
                return $this->update_portfolio($variables);
                break;
            case 'usun-portfolio':
                return $this->delete_portfolio($variables);
                break;
            default:
                return $this->default_action($variables);
                break;
        }
    }
    
    
    private function delete_portfolio(array $variables = null){
        $this->action_handler = new Portfoliomanager_Model_Deleteportfolioitem;
        return $this->action_handler->main($variables);
    }
    
    private function update_portfolio(array $variables = null){
        $this->action_handler = new Portfoliomanager_Model_Updateportfolioitem;
        return $this->action_handler->main($variables);
    }
    
    private function edit_portfolio(array $variables = null){
        $page = $this->other_data($variables);
        $this->action_handler = new Portfoliomanager_Data_Getcurrentportfolio;
        $page['content'] = $this->action_handler->main($variables);
        return $page;
    }

    private function insert_portfolio(array $variables = null){
        $this->action_handler = new Portfoliomanager_Model_Insertportfolioitem;
        return $this->action_handler->main($variables);
    }
    
    private function add_portfolio(array $variables = null){
        $page = $this->other_data($variables);
        return $page;
    }
    
    private function other_data(array $variables = null){
        $this->core_controller_csrftoken = new Core_Controller_Csrftoken;
        $this->get_access_level = new Privileges_Data_Getpriviligeslist;
        $this->get_account_status = new Accountsstatus_Data_Getaccountsstatus;
        $this->get_subcategories = new Subcategorymanager_Data_Getallsubcategories;
        $this->get_images = new Imageupload_Data_Getallimages;
        
        $page['csrf_token'] = $this->core_controller_csrftoken->main($variables);
        $page['access_level'] = $this->get_access_level->main($variables);
        $page['status'] = $this->get_account_status->main($variables);
        $page['subcategory'] = $this->get_subcategories->main($variables);
        $page['image'] = $this->get_images->main($variables);
        
        $page['template'] = WEB_ROOT_FOLDER."portfoliomanager/views/additem.php";
        
        return $page;
    }
    
    private function default_action(array $variables = null){
        unset($variables['get']);
        $this->action_handler = new Portfoliomanager_Model_Portfoliomanager;
        return $this->action_handler->main($variables);
    }

}
